package controller

import (
	"golang.org/x/crypto/bcrypt"
	"kf/models/dao"
	"kf/models/entity"
)

type AuthController struct {
	SysUserDao   *dao.SysUserDao
	UserRolesDao *dao.SysUserRolesDao
}

func (authController *AuthController) CheckKefuPass(username string, password string) (entity.SysUser, entity.SysUserRole, bool) {
	var uRole entity.SysUserRole
	info, err := authController.SysUserDao.FindSysUserByUserName(username)
	if err != nil || info.ID == 0 {
		return info, uRole, false
	}
	if info.UserName == "" {
		return info, uRole, false
	}
	err = bcrypt.CompareHashAndPassword([]byte(info.Password), []byte(password))
	if err != nil {
		return entity.SysUser{}, entity.SysUserRole{}, false
	}
	uRole = authController.UserRolesDao.FindRoleByUserId(info.ID)
	return info, uRole, true
}
